package com.googlecode.pwlodars.piteststat.writer.content;

import java.io.File;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.googlecode.pwlodars.piteststat.filesystembridge.TextResourcesConnector;

public class PitResultsFilesReader {

	private TextResourcesConnector textResourcesConnector;

	public PitResultsFilesReader(TextResourcesConnector textResourcesConnector) {
		super();
		this.textResourcesConnector = textResourcesConnector;
	}
	
	public List<PitResultFileInfo> readResultFiles(List<File> folders) {
		List<PitResultFileInfo> resultContents=new LinkedList<PitResultFileInfo>();
		for (File folder : folders) {
			File indexFile = new File(folder,"index.html");
			PitResultFileInfo pitResultFileInfo = readSingleFile(indexFile);
			resultContents.add(pitResultFileInfo);
		}
		return resultContents;
	}

	public PitResultFileInfo readSingleFile(File indexFile) {
		String resultFileContent = textResourcesConnector.readTextFromFile(indexFile);
		//TODO move to filesystemconnector
		PitResultFileInfo pitResultFileInfo=new PitResultFileInfo(resultFileContent, new Date(indexFile.lastModified()));
		return pitResultFileInfo;
	}
	
}
